package com.service.impl;

import com.constant.Constant;
import com.entity.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.UserMapper;
import com.service.UserService;
import com.vo.FindBackUserVO;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 陈忠杰
 * @Date: 2021/07/02/15:36
 * @Description:
 */
@Service
public class UserServiceImpl implements UserService {

    private static final Logger loggle = Logger.getLogger(UserServiceImpl.class);

    @Autowired
    UserMapper userMapper;

    @Override
    public boolean isUser(String login_name, String password) {
        int i = userMapper.selUser(login_name, password);
        if (i != 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public PageInfo<User> getUserByInfo(FindBackUserVO findBackUserVO) {
        PageHelper.startPage(findBackUserVO.getPageNo(), Constant.PAGE_SIZE_COURSE);
        List<User> users = userMapper.selUserByInfo(findBackUserVO);
        PageInfo<User> userPageInfo = new PageInfo<>(users);
        return userPageInfo;
    }

    @Override
    public User getUserById(int id) {
        User user = userMapper.selUserById(id);
        return user;
    }

    @Override
    public void changeUserByInfo(User user) {
        userMapper.updUserByInfo(user);
    }

    @Override
    public void changeUserStatus(User user) {
        loggle.info("前段传入的用户状态为"+user.getStatus());
        if (user.getStatus()!=1){
            user.setStatus(1);
        }else {
            user.setStatus(0);
        }
        loggle.info("将要修改用户状态为"+user.getStatus());
        userMapper.updUserStatus(user);
    }
}
